package com.shuqi.common;

import com.shuqi.application.ShuqiApplication;
import com.shuqi.common.utils.Log4an;
import com.shuqi.service.ConnectionChangeReceiver;

/**
 * 网络变化提醒相关
 * 
 * @author hxp
 * 
 */
public class NetNotify {

    public static final int DOWNLOAD_BOOK_OFFLINE = 1; // 全本下载
    public static final int DOWNLOAD_BOOK_READ = 2; // 全本购买

    public static final int DOWNLOAD_BOOK_SHELF = 3; // 书架下载

    public static final int DOWNLOAD_BOOK_WEBKIT = 4;// webkit离线下载

    private int mNetType = ConnectionChangeReceiver.NET_TYPE_NO;// 网络类型
    private boolean mBookOffLine = true; // 全本下载默认提醒
    private boolean mBookRead = true; // 全本购买默认提醒
    private boolean mBookShelf = true; // 书架下载默认提醒
    private boolean mBookWebkit = true;// webkit下载默认提醒

    private static NetNotify instance = new NetNotify();

    public static NetNotify getInstance() {
        return instance;
    }

    private void initNetState(){
            mBookOffLine = true;
            mBookRead = true;
            mBookShelf = true;
            mBookWebkit = true;
    }
    
    /**
     * 判断用户使用非wifi网络的情况下是否需要提醒
     * 
     * @return
     */
    public boolean isNeedNotifyNoWifi(int methodId) {
        mNetType = ConnectionChangeReceiver.getNetType(ShuqiApplication.getContext());
        if (mNetType == ConnectionChangeReceiver.NET_TYPE_NO
                || mNetType == ConnectionChangeReceiver.NET_TYPE_WIFI) {
            initNetState();
            return false;
        } else {
            boolean result = true;
            switch (methodId) {
                case DOWNLOAD_BOOK_OFFLINE:
                    result = mBookOffLine;
                    break;
                case DOWNLOAD_BOOK_READ:
                    result = mBookRead;
                    break;
                case DOWNLOAD_BOOK_SHELF:
                    result = mBookShelf;
                    break;
                case DOWNLOAD_BOOK_WEBKIT:
                    result = mBookWebkit;
                    break;
                default:
                    break;
            }
            return result;
        }
    }

    /**
     * 点击确认按钮，更改通知状态
     * 
     * @param methodId
     */
    public void changeNotifyState(int methodId) {
        switch (methodId) {
            case DOWNLOAD_BOOK_OFFLINE:
                mBookOffLine = false;
                break;
            case DOWNLOAD_BOOK_READ:
                mBookRead = false;
                break;
            case DOWNLOAD_BOOK_SHELF:
                mBookShelf = false;
                break;
            case DOWNLOAD_BOOK_WEBKIT:
                mBookWebkit = false;
                break;
            default:
                break;
        }
    }
}
